<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/snowzhao/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/snowzhao/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/snowzhao/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/snowzhao/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/snowzhao/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/snowzhao/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/snowzhao/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="android,">










<meta name="description" content="先看效果图实际是圆的，由于录制视频视频尺寸小于实际宽度，所以看着有点像椭圆； 需求分析1、需求左右点击可以切换月份，不需要左右滑动切换，时间紧迫就按需求完成功能；2、打卡日期选中如图，单个选中、左右相邻选中和换行样式如图；3、当前日期选中，点击也需要选中效果；4、月份可能会显示5行或6行，控制总高度不变，动态设置单行日期的高度，选中要是的宽高；5、根据年月获取当月有多少天，再根据第一天在星期几，当">
<meta name="keywords" content="android">
<meta property="og:type" content="article">
<meta property="og:title" content="自定义打卡日历">
<meta property="og:url" content="https://vincent_zyt.gitee.io/snowzhao/2019/12/02/自定义打卡日历/index.html">
<meta property="og:site_name" content="snowzhao博客">
<meta property="og:description" content="先看效果图实际是圆的，由于录制视频视频尺寸小于实际宽度，所以看着有点像椭圆； 需求分析1、需求左右点击可以切换月份，不需要左右滑动切换，时间紧迫就按需求完成功能；2、打卡日期选中如图，单个选中、左右相邻选中和换行样式如图；3、当前日期选中，点击也需要选中效果；4、月份可能会显示5行或6行，控制总高度不变，动态设置单行日期的高度，选中要是的宽高；5、根据年月获取当月有多少天，再根据第一天在星期几，当">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20191129185942556.gif">
<meta property="og:updated_time" content="2019-12-02T07:09:50.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="自定义打卡日历">
<meta name="twitter:description" content="先看效果图实际是圆的，由于录制视频视频尺寸小于实际宽度，所以看着有点像椭圆； 需求分析1、需求左右点击可以切换月份，不需要左右滑动切换，时间紧迫就按需求完成功能；2、打卡日期选中如图，单个选中、左右相邻选中和换行样式如图；3、当前日期选中，点击也需要选中效果；4、月份可能会显示5行或6行，控制总高度不变，动态设置单行日期的高度，选中要是的宽高；5、根据年月获取当月有多少天，再根据第一天在星期几，当">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20191129185942556.gif">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/snowzhao/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://vincent_zyt.gitee.io/snowzhao/2019/12/02/自定义打卡日历/">





  <title>自定义打卡日历 | snowzhao博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/snowzhao/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">snowzhao博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">蜕变</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-首页">
          <a href="/snowzhao/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-归档">
          <a href="/snowzhao/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-标签">
          <a href="/snowzhao/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-分类">
          <a href="/snowzhao/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://vincent_zyt.gitee.io/snowzhao/snowzhao/2019/12/02/自定义打卡日历/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="snowzhao">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/snowzhao/images/photo.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="snowzhao博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">自定义打卡日历</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-02T15:09:50+08:00">
                2019-12-02
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/snowzhao/categories/android/" itemprop="url" rel="index">
                    <span itemprop="name">android</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2.1k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  11
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="先看效果图"><a href="#先看效果图" class="headerlink" title="先看效果图"></a>先看效果图</h1><p>实际是圆的，由于录制视频视频尺寸小于实际宽度，所以看着有点像椭圆；<br><img src="https://img-blog.csdnimg.cn/20191129185942556.gif" alt="在这里插入图片描述"></p>
<h1 id="需求分析"><a href="#需求分析" class="headerlink" title="需求分析"></a>需求分析</h1><p>1、需求左右点击可以切换月份，不需要左右滑动切换，时间紧迫就按需求完成功能；<br>2、打卡日期选中如图，单个选中、左右相邻选中和换行样式如图；<br>3、当前日期选中，点击也需要选中效果；<br>4、月份可能会显示5行或6行，控制总高度不变，动态设置单行日期的高度，选中要是的宽高；<br>5、根据年月获取当月有多少天，再根据第一天在星期几，当月数据从此处开始添加</p>
<h1 id="核心代码"><a href="#核心代码" class="headerlink" title="核心代码"></a>核心代码</h1><h2 id="星期的实现"><a href="#星期的实现" class="headerlink" title="星期的实现"></a>星期的实现</h2><p>星期根据控件的宽均分显示，高度居中显示</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">public class WeekBarView extends AppCompatTextView &#123;</span><br><span class="line">    public String[] days = &#123;&quot;日&quot;, &quot;一&quot;, &quot;二&quot;, &quot;三&quot;, &quot;四&quot;, &quot;五&quot;, &quot;六&quot;&#125;;</span><br><span class="line">    private TextPaint textPaint;</span><br><span class="line"></span><br><span class="line">    public WeekBarView(Context context) &#123;</span><br><span class="line">        this(context, null);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public WeekBarView(Context context, @Nullable AttributeSet attrs) &#123;</span><br><span class="line">        super(context, attrs);</span><br><span class="line">        textPaint = getPaint();</span><br><span class="line">        textPaint.setTextAlign(Paint.Align.CENTER);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) &#123;</span><br><span class="line">        super.onMeasure(widthMeasureSpec, heightMeasureSpec);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void onDraw(Canvas canvas) &#123;</span><br><span class="line">        super.onDraw(canvas);</span><br><span class="line"></span><br><span class="line">        int paddingLeft = getPaddingLeft();</span><br><span class="line">        int paddingRight = getPaddingRight();</span><br><span class="line"></span><br><span class="line">        int paddingTop = getPaddingTop();</span><br><span class="line">        int paddingBottom = getPaddingBottom();</span><br><span class="line"></span><br><span class="line">        int width = getMeasuredWidth() - paddingRight - paddingLeft;</span><br><span class="line">        int height = getMeasuredHeight() - paddingTop - paddingBottom;</span><br><span class="line">        for (int i = 0; i &lt; days.length; i++) &#123;</span><br><span class="line">            Rect rect = new Rect(paddingLeft + (i * width / days.length), paddingTop, paddingLeft + ((i + 1) * width / days.length), paddingTop + height);</span><br><span class="line">            Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();</span><br><span class="line">            float top = fontMetrics.top;</span><br><span class="line">            float bottom = fontMetrics.bottom;</span><br><span class="line">            int baseLineY = (int) (rect.centerY() - top / 2 - bottom / 2);</span><br><span class="line">            canvas.drawText(days[i], rect.centerX(), baseLineY, textPaint);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="日历实现"><a href="#日历实现" class="headerlink" title="日历实现"></a>日历实现</h2><p>日期的工具类</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line">     * 获取对应年月的天数</span><br><span class="line">     *</span><br><span class="line">     * @param year</span><br><span class="line">     * @param month</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public int getMonthLastDay(int year, int month) &#123;</span><br><span class="line">        Calendar a = Calendar.getInstance();</span><br><span class="line">        a.set(Calendar.YEAR, year);</span><br><span class="line">        a.set(Calendar.MONTH, month - 1);</span><br><span class="line">        a.set(Calendar.DATE, 1);//把日期设置为当月第一天</span><br><span class="line">        a.roll(Calendar.DATE, -1);//日期回滚一天，也就是最后一天</span><br><span class="line">        return a.get(Calendar.DATE);</span><br><span class="line">    &#125;</span><br><span class="line">    //获取日历相关数据</span><br><span class="line"> Calendar calendar = Calendar.getInstance();</span><br><span class="line"> //当天在当月中第几天 2、12、23</span><br><span class="line"> int currDay = calendar.get(Calendar.DAY_OF_MONTH);</span><br><span class="line"> //当月是第几个月 8、11</span><br><span class="line"> int currMouth = calendar.get(Calendar.MONTH) + 1;</span><br><span class="line"> //当前年份 2019</span><br><span class="line">  int currYear = calendar.get(Calendar.YEAR);</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line">     * 对应年月的一号是星期几</span><br><span class="line">     *</span><br><span class="line">     * @param year</span><br><span class="line">     * @param month</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public int getFirstDayOfWeek(int year, int month) &#123;</span><br><span class="line">        Calendar calendar = Calendar.getInstance();</span><br><span class="line">        calendar.set(year, month - 1, 0);</span><br><span class="line">        int currYear = calendar.get(Calendar.YEAR);</span><br><span class="line">        int currMouth = calendar.get(Calendar.MONTH) + 1;</span><br><span class="line">        int currDay = calendar.get(Calendar.DAY_OF_MONTH);</span><br><span class="line">        int i1 = calendar.get(Calendar.DAY_OF_WEEK);//这就是星期几</span><br><span class="line">        if (i1 == 7) &#123;</span><br><span class="line">            i1 = 0;</span><br><span class="line">        &#125;</span><br><span class="line">        return i1;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>设置日历的数据核心代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">//获取日历布局的宽高，后面用于item的宽高和选中宽高设置</span><br><span class="line">   @Override</span><br><span class="line">    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) &#123;</span><br><span class="line">        super.onMeasure(widthMeasureSpec, heightMeasureSpec);</span><br><span class="line">        totalHeight = getMeasuredHeight();</span><br><span class="line">        totalWidth = getMeasuredWidth();</span><br><span class="line">//        Log.e(&quot;snow_m&quot;, &quot;=========&quot; + totalHeight);</span><br><span class="line">    &#125;</span><br><span class="line"> /**</span><br><span class="line">     * 重新设置日历数据</span><br><span class="line">     *</span><br><span class="line">     * @param year</span><br><span class="line">     * @param month</span><br><span class="line">     */</span><br><span class="line">    public void resetCalendarData(int year, int month, List&lt;ClockInBean&gt; clockInList) &#123;</span><br><span class="line">        calendarDataList.clear();</span><br><span class="line">        int monthLastDay = CalendarUtils.init().getMonthLastDay(year, month);</span><br><span class="line">        int dayOfWeek = CalendarUtils.init().getFirstDayOfWeek(year, month);</span><br><span class="line">        int dayOfMonth = CalendarUtils.init().getTodayOfMonth();</span><br><span class="line">        //当前页面显示上月的数据，或者空</span><br><span class="line">        for (int i = 0; i &lt; dayOfWeek; i++) &#123;</span><br><span class="line">            CalendarData calendarData = new CalendarData();</span><br><span class="line">            calendarData.setSolarNum(&quot;&quot;);</span><br><span class="line">            calendarDataList.add(calendarData);</span><br><span class="line">        &#125;</span><br><span class="line">        //设置当月数据</span><br><span class="line">        for (int i = 0; i &lt; monthLastDay; i++) &#123;</span><br><span class="line">            CalendarData calendarData = new CalendarData();</span><br><span class="line">            calendarData.setYearMD(year + &quot;-&quot; + month + &quot;-&quot; + CalendarUtils.init().addZeroBefore(i + 1));</span><br><span class="line">            calendarData.setSolarNum(String.valueOf(i + 1));</span><br><span class="line">            calendarDataList.add(calendarData);</span><br><span class="line">        &#125;</span><br><span class="line">//        calendarAdapter.setTodayPosition(dayOfMonth + dayOfWeek, CalendarUtils.init().getTodayMonth());</span><br><span class="line">        //计算共几行</span><br><span class="line">        int rowNum = (int) Math.ceil((monthLastDay + dayOfWeek) / 7f);</span><br><span class="line">        calendarAdapter.setItemWidthHeight(totalHeight / rowNum, rowNum, totalWidth / 7);</span><br><span class="line"></span><br><span class="line">        CalendarUtils.init().addClockInInfoToCalendarInfo(year, month, dayOfWeek, calendarDataList, clockInList);</span><br><span class="line"></span><br><span class="line">        calendarAdapter.setDataList(calendarDataList);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>适配器实现功能核心代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br></pre></td><td class="code"><pre><span class="line">public class AdapterCalendarItem extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; &#123;</span><br><span class="line">    private Context mContext;</span><br><span class="line">    private List&lt;CalendarData&gt; dataList;</span><br><span class="line">    private int itemHeight;</span><br><span class="line">    private int itemWidth;</span><br><span class="line">    private int onlySelectWH;</span><br><span class="line">    CalendarItemClickListener itemClickListener;</span><br><span class="line">    //当前点击日期 2019-11-02</span><br><span class="line">    private String currentClickDate;</span><br><span class="line">    //当前日期 2019-11-02</span><br><span class="line">    private String todayDate;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    public AdapterCalendarItem(Context mContext, CalendarItemClickListener itemClickListener) &#123;</span><br><span class="line">        this.mContext = mContext;</span><br><span class="line">        this.itemClickListener = itemClickListener;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @NonNull</span><br><span class="line">    @Override</span><br><span class="line">    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) &#123;</span><br><span class="line">        View view = LayoutInflater.from(mContext).inflate(R.layout.item_calendar_adapter, null);</span><br><span class="line">        return new ViewHolder(view);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setDataList(List&lt;CalendarData&gt; dataList) &#123;</span><br><span class="line">        this.dataList = dataList;</span><br><span class="line">        notifyDataSetChanged();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 设置今天日期</span><br><span class="line">     *</span><br><span class="line">     * @param todayPosition</span><br><span class="line">     */</span><br><span class="line">    public void setTodayPosition(String todayPosition) &#123;</span><br><span class="line">        this.todayDate = todayPosition;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 设置item的高度  总行数</span><br><span class="line">     *</span><br><span class="line">     * @param itemHeight</span><br><span class="line">     * @param rowNum</span><br><span class="line">     */</span><br><span class="line">    public void setItemWidthHeight(int itemHeight, int rowNum, int itemWidth) &#123;</span><br><span class="line">        this.itemHeight = itemHeight;</span><br><span class="line">        this.itemWidth = itemWidth;</span><br><span class="line">        onlySelectWH = (int) (itemHeight - TextViewUtils.init().dp2px(mContext, 12) * (5 / 6f));</span><br><span class="line">        if (onlySelectWH &gt; itemWidth) &#123;</span><br><span class="line">            onlySelectWH = itemWidth;</span><br><span class="line">        &#125;</span><br><span class="line">//        Log.e(&quot;snow_m&quot;, &quot;====itemHeight=====&quot; + itemHeight);</span><br><span class="line">//        Log.e(&quot;snow_m&quot;, &quot;====itemWidth=====&quot; + itemWidth);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    public void setCurrentClickDate(String clickDate) &#123;</span><br><span class="line">        this.currentClickDate = clickDate;</span><br><span class="line">        notifyDataSetChanged();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) &#123;</span><br><span class="line">        final CalendarData data = dataList.get(position);</span><br><span class="line">        ViewHolder vh = (ViewHolder) holder;</span><br><span class="line">        //设置item的高</span><br><span class="line">        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) vh.root_view.getLayoutParams();</span><br><span class="line">        layoutParams.height = itemHeight;</span><br><span class="line">        vh.root_view.setLayoutParams(layoutParams);</span><br><span class="line">        //设置选中的宽高</span><br><span class="line">        RelativeLayout.LayoutParams onlySelectViewParams = (RelativeLayout.LayoutParams) vh.onlySelectView.getLayoutParams();</span><br><span class="line">        onlySelectViewParams.height = onlySelectWH;</span><br><span class="line">        onlySelectViewParams.width = onlySelectWH;</span><br><span class="line">        vh.onlySelectView.setLayoutParams(onlySelectViewParams);</span><br><span class="line"></span><br><span class="line">        vh.tv_num.setText(data.getSolarNum());</span><br><span class="line">        //设置选中的===已签到状态</span><br><span class="line">        if (data.getClockInBean() != null) &#123;</span><br><span class="line">            vh.tv_num.setTextColor(mContext.getResources().getColor(R.color.tt_FF8820));</span><br><span class="line">            setSelectedView(vh.selectedView, position);</span><br><span class="line">            vh.ivRemind.setVisibility(View.VISIBLE);</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            vh.tv_num.setTextColor(mContext.getResources().getColor(R.color.tt_33333));</span><br><span class="line">            vh.ivRemind.setVisibility(View.INVISIBLE);</span><br><span class="line">            vh.selectedView.setBackground(null);</span><br><span class="line">        &#125;</span><br><span class="line">        //设置当前点击的效果</span><br><span class="line">        if (!TextUtils.isEmpty(currentClickDate) &amp;&amp; currentClickDate.equals(data.getYearMD())) &#123;</span><br><span class="line">            vh.ivRemind.setColorFilter(mContext.getResources().getColor(R.color.tt_white));</span><br><span class="line">            vh.onlySelectView.setBackgroundResource(R.drawable.bg_ff8820_circle);</span><br><span class="line">            vh.tv_num.setTextColor(mContext.getResources().getColor(R.color.tt_white));</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            vh.ivRemind.setColorFilter(mContext.getResources().getColor(R.color.tt_FF8820));</span><br><span class="line">            vh.onlySelectView.setBackground(null);</span><br><span class="line">        &#125;</span><br><span class="line">        //设置今天对应的效果</span><br><span class="line">        if (!TextUtils.isEmpty(data.getYearMD()) &amp;&amp; data.getYearMD().equals(todayDate)) &#123;</span><br><span class="line">            vh.ivRemind.setColorFilter(mContext.getResources().getColor(R.color.tt_white));</span><br><span class="line">            vh.onlySelectView.setBackgroundResource(R.drawable.bg_ff8820_circle);</span><br><span class="line">            vh.tv_num.setTextColor(mContext.getResources().getColor(R.color.tt_white));</span><br><span class="line">        &#125;</span><br><span class="line">        //item点击</span><br><span class="line">        vh.root_view.setOnClickListener(new View.OnClickListener() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void onClick(View view) &#123;</span><br><span class="line">                if (itemClickListener != null) &#123;</span><br><span class="line">                    itemClickListener.itemClick(data, position);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 根据情况显示已选中（打卡）的样式</span><br><span class="line">     *</span><br><span class="line">     * @param selectedView</span><br><span class="line">     * @param position</span><br><span class="line">     */</span><br><span class="line">    private void setSelectedView(View selectedView, int position) &#123;</span><br><span class="line">        if (position % 7 == 0) &#123;//最左边的数字</span><br><span class="line">            drawSelectView(selectedView, nextIsSelected(position, dataList) ? 3 : 0);</span><br><span class="line">        &#125; else if (position % 7 == 6) &#123;//最右边的数字</span><br><span class="line">            drawSelectView(selectedView, lastIsSelected(position, dataList) ? 2 : 0);</span><br><span class="line">        &#125; else &#123;//中间数据</span><br><span class="line">            boolean left = lastIsSelected(position, dataList);</span><br><span class="line">            boolean right = nextIsSelected(position, dataList);</span><br><span class="line">            if (left &amp;&amp; right) &#123;</span><br><span class="line">                drawSelectView(selectedView, 1);</span><br><span class="line">            &#125; else if (left) &#123;</span><br><span class="line">                drawSelectView(selectedView, 2);</span><br><span class="line">            &#125; else if (right) &#123;</span><br><span class="line">                drawSelectView(selectedView, 3);</span><br><span class="line">            &#125; else &#123;</span><br><span class="line">                drawSelectView(selectedView, 0);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 绘制选中的样式</span><br><span class="line">     *</span><br><span class="line">     * @param selectedView</span><br><span class="line">     * @param flag</span><br><span class="line">     */</span><br><span class="line">    private void drawSelectView(View selectedView, int flag) &#123;</span><br><span class="line">        //设置选中的宽高</span><br><span class="line">        RelativeLayout.LayoutParams onlySelectViewParams = (RelativeLayout.LayoutParams) selectedView.getLayoutParams();</span><br><span class="line">        onlySelectViewParams.height = onlySelectWH;</span><br><span class="line">        if (flag == 1) &#123;//画全整个矩形</span><br><span class="line">            selectedView.setBackgroundResource(R.color.tt_ffe2c9);</span><br><span class="line">            onlySelectViewParams.width = itemWidth + 5;</span><br><span class="line">        &#125; else if (flag == 2) &#123; //左矩形 右圆==靠左</span><br><span class="line">            selectedView.setBackgroundResource(R.drawable.bg_ffe2c9_right_circle);</span><br><span class="line">            onlySelectViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);</span><br><span class="line">            onlySelectViewParams.width = itemWidth / 2 + onlySelectWH / 2;</span><br><span class="line">        &#125; else if (flag == 3) &#123;//右矩形 左圆====靠右</span><br><span class="line">            selectedView.setBackgroundResource(R.drawable.bg_ffe2c9_left_circle);</span><br><span class="line">            onlySelectViewParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);</span><br><span class="line">            onlySelectViewParams.width = itemWidth / 2 + onlySelectWH / 2;</span><br><span class="line">        &#125; else &#123; //圆形</span><br><span class="line">            selectedView.setBackgroundResource(R.drawable.bg_ffe2c9_circle);</span><br><span class="line">            onlySelectViewParams.width = onlySelectWH;</span><br><span class="line">            onlySelectViewParams.addRule(RelativeLayout.CENTER_IN_PARENT);</span><br><span class="line">        &#125;</span><br><span class="line">        selectedView.setLayoutParams(onlySelectViewParams);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 上一条数据是否被选中</span><br><span class="line">     *</span><br><span class="line">     * @param position</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    private boolean lastIsSelected(int position, List&lt;CalendarData&gt; dataList) &#123;</span><br><span class="line">        if (dataList == null) &#123;</span><br><span class="line">            return false;</span><br><span class="line">        &#125;</span><br><span class="line">        CalendarData lastData = null;</span><br><span class="line">        if (position &gt; 0) &#123;</span><br><span class="line">            lastData = dataList.get(position - 1);</span><br><span class="line">        &#125;</span><br><span class="line">        if (lastData == null || lastData.getClockInBean() == null) &#123;</span><br><span class="line">            return false;</span><br><span class="line">        &#125;</span><br><span class="line">        return true;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 下一条数据是否被选中</span><br><span class="line">     *</span><br><span class="line">     * @param position</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    private boolean nextIsSelected(int position, List&lt;CalendarData&gt; dataList) &#123;</span><br><span class="line">        if (dataList == null) &#123;</span><br><span class="line">            return false;</span><br><span class="line">        &#125;</span><br><span class="line">        CalendarData nextData = null;</span><br><span class="line">        if (position &lt; dataList.size() - 1) &#123;</span><br><span class="line">            nextData = dataList.get(position + 1);</span><br><span class="line">        &#125;</span><br><span class="line">        if (nextData == null || nextData.getClockInBean() == null) &#123;</span><br><span class="line">            return false;</span><br><span class="line">        &#125;</span><br><span class="line">        return true;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public int getItemCount() &#123;</span><br><span class="line">        return dataList == null ? 0 : dataList.size();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    class ViewHolder extends RecyclerView.ViewHolder &#123;</span><br><span class="line">        TextView tv_num;</span><br><span class="line">        RelativeLayout root_view;</span><br><span class="line">        //点击或者单个选中</span><br><span class="line">        View onlySelectView;</span><br><span class="line">        //已签到选中</span><br><span class="line">        View selectedView;</span><br><span class="line">        ImageView ivRemind;</span><br><span class="line"></span><br><span class="line">        public ViewHolder(@NonNull View itemView) &#123;</span><br><span class="line">            super(itemView);</span><br><span class="line">            tv_num = itemView.findViewById(R.id.tv_num);</span><br><span class="line">            root_view = itemView.findViewById(R.id.root_view);</span><br><span class="line">            onlySelectView = itemView.findViewById(R.id.only_select_view);</span><br><span class="line">            selectedView = itemView.findViewById(R.id.selected_view);</span><br><span class="line">            ivRemind = itemView.findViewById(R.id.iv_remind);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public interface CalendarItemClickListener &#123;</span><br><span class="line">        void itemClick(CalendarData data, int position);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>对应的适配器xml代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">    android:layout_height=&quot;match_parent&quot;&gt;</span><br><span class="line"></span><br><span class="line">    &lt;RelativeLayout</span><br><span class="line">        android:id=&quot;@+id/root_view&quot;</span><br><span class="line">        android:layout_width=&quot;match_parent&quot;</span><br><span class="line">        android:layout_height=&quot;match_parent&quot;&gt;</span><br><span class="line"></span><br><span class="line">        &lt;View</span><br><span class="line">            android:id=&quot;@+id/selected_view&quot;</span><br><span class="line">            android:layout_width=&quot;match_parent&quot;</span><br><span class="line">            android:layout_height=&quot;wrap_content&quot;</span><br><span class="line">            android:layout_centerInParent=&quot;true&quot; /&gt;</span><br><span class="line"></span><br><span class="line">        &lt;View</span><br><span class="line">            android:id=&quot;@+id/only_select_view&quot;</span><br><span class="line">            android:layout_width=&quot;wrap_content&quot;</span><br><span class="line">            android:layout_height=&quot;wrap_content&quot;</span><br><span class="line">            android:layout_centerInParent=&quot;true&quot; /&gt;</span><br><span class="line"></span><br><span class="line">        &lt;LinearLayout</span><br><span class="line">            android:layout_width=&quot;wrap_content&quot;</span><br><span class="line">            android:layout_height=&quot;wrap_content&quot;</span><br><span class="line">            android:layout_centerInParent=&quot;true&quot;</span><br><span class="line">            android:gravity=&quot;center&quot;</span><br><span class="line">            android:orientation=&quot;vertical&quot;&gt;</span><br><span class="line"></span><br><span class="line">            &lt;ImageView</span><br><span class="line">                android:layout_width=&quot;@dimen/margin_08&quot;</span><br><span class="line">                android:layout_height=&quot;@dimen/margin_07&quot; /&gt;</span><br><span class="line"></span><br><span class="line">            &lt;TextView</span><br><span class="line">                android:id=&quot;@+id/tv_num&quot;</span><br><span class="line">                android:layout_width=&quot;wrap_content&quot;</span><br><span class="line">                android:layout_height=&quot;wrap_content&quot;</span><br><span class="line">                android:textSize=&quot;@dimen/text_size_18&quot; /&gt;</span><br><span class="line"></span><br><span class="line">            &lt;ImageView</span><br><span class="line">                android:id=&quot;@+id/iv_remind&quot;</span><br><span class="line">                android:layout_width=&quot;@dimen/margin_08&quot;</span><br><span class="line">                android:layout_height=&quot;@dimen/margin_07&quot;</span><br><span class="line">                android:src=&quot;@mipmap/icon_clock_in_complete&quot;</span><br><span class="line">                android:visibility=&quot;gone&quot;/&gt;</span><br><span class="line">        &lt;/LinearLayout&gt;</span><br><span class="line">    &lt;/RelativeLayout&gt;</span><br><span class="line">&lt;/RelativeLayout&gt;</span><br></pre></td></tr></table></figure>

<p>其实github也有很多好的日历依赖库，但项目样式和需求问题只能自定义实现，由于时间问题，临时是只实现左右切换，没有做左右滑动切换，可以使用ViewPager进行包装实现左右滑动切换，对数据还需要整理下才能更好适用自己的项目；</p>
<p><a href="https://download.csdn.net/download/qq_31796651/12010254" target="_blank" rel="noopener">demo代码</a></p>

      
    </div>
    
    
    

 
<div>
  
    <div>
    
        <div style="text-align:center;color: #666;font-size:16px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
  
</div>

    

    

    
    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/snowzhao/tags/android/" rel="tag"># android</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/snowzhao/2019/09/04/TBS浏览器X5内核使用/" rel="next" title="使用腾讯的TBS浏览器X5内核的集成加载pdf等文件">
                <i class="fa fa-chevron-left"></i> 使用腾讯的TBS浏览器X5内核的集成加载pdf等文件
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/snowzhao/2019/12/02/js-数据类型转换/" rel="prev" title="js 数据类型转换">
                js 数据类型转换 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/snowzhao/images/photo.png" alt="snowzhao">
            
              <p class="site-author-name" itemprop="name">snowzhao</p>
              <p class="site-description motion-element" itemprop="description">给自己每天浇点水,迟早会长成一棵大树</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/snowzhao/archives">
              
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/snowzhao/categories/index.html">
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/snowzhao/tags/index.html">
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zhaoyingtao" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/qq_31796651" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-stack-overflow"></i>CSDN</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#先看效果图"><span class="nav-text">先看效果图</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#需求分析"><span class="nav-text">需求分析</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#核心代码"><span class="nav-text">核心代码</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#星期的实现"><span class="nav-text">星期的实现</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#日历实现"><span class="nav-text">日历实现</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">snowzhao</span>

<!-- 取消英文统计数字
  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">7.4k</span>
  
-->
</div>
<!-- 取消默认 由 hexo 强力驱动 | 主题 next。pisces v5.1.4

  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>



-->



<span class="post-meta-divider"> 坚持 </span>

<span class="post-meta-divider"> | </span>

<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共 7.4k 字</span>
</div>

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/snowzhao/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/snowzhao/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/snowzhao/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/snowzhao/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/snowzhao/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/snowzhao/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/snowzhao/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/snowzhao/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/snowzhao/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

<script src="/snowzhao/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/snowzhao/live2dw/assets/assets/z16.model.json"},"display":{"position":"right","width":300,"height":500},"mobile":{"show":false},"log":false});</script></body>
</html>
